package org.example.managementsystem.service;

import org.example.managementsystem.model.Production_Submission_Detail;
import org.example.managementsystem.repository.Production_Submission_DetailDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Production_Submission_DetailService {
    private final Production_Submission_DetailDao submissionDetailDao;

    @Autowired
    public Production_Submission_DetailService(Production_Submission_DetailDao submissionDetailDao) {
        this.submissionDetailDao = submissionDetailDao;
    }

    public Production_Submission_Detail addSubmissionDetail(Production_Submission_Detail detail) {
        int id = submissionDetailDao.insertProduction_Submission_Detail(detail);
        detail.setDetail_id(id);
        return detail;
    }

    public boolean updateSubmissionDetail(Production_Submission_Detail detail) {
        return submissionDetailDao.updateProduction_Submission_Detail(detail) > 0;
    }

    public boolean deleteSubmissionDetail(int detailId) {
        return submissionDetailDao.deleteProduct_Plan_Detail(detailId) > 0;
    }

    public Production_Submission_Detail getSubmissionDetailById(int detailId) {
        return submissionDetailDao.getProduction_Submission_DetailById(detailId);
    }

    public List<Production_Submission_Detail> getAllSubmissionDetails() {
        return submissionDetailDao.getAllProduction_Submission_Details();
    }

    public List<Production_Submission_Detail> getDetailsBySubmissionId(int submissionId) {
        return submissionDetailDao.getProduction_Submission_DetailsBysubmission_id(submissionId);
    }

    public boolean updateSubmissionDetailById(Production_Submission_Detail detail) {
        return submissionDetailDao.updateProduction_Submission_Detail(detail) > 0;
    }
}